package com.yachang.qym.usbhost;

import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.util.Log;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.baidu.mapapi.SDKInitializer;
import com.github.nkzawa.socketio.client.IO;
import com.snappydb.DB;
import com.snappydb.SnappyDB;
import com.snappydb.SnappydbException;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import java.net.URISyntaxException;

import static com.yachang.qym.usbhost.utils.API.mSocket;
import static com.yachang.qym.usbhost.utils.API.serverUrl;

/**
 * Created by qym on 2015/12/19.
 */
public class UsbApplication extends Application{

    private static RequestQueue mQueue;
    private static Context mContext;
    public static DB snappydb;


    @Override
    public void onCreate() {
        try {
            refWatcher=LeakCanary.install(this);
            snappydb = new SnappyDB.Builder(this)
                    .directory(Environment.getExternalStorageDirectory().getAbsolutePath()) //optional
                    .name("yachang")//optional
                    .build();
        } catch (SnappydbException e) {
            e.printStackTrace();
            try {
                snappydb = new SnappyDB.Builder(this)
                        .directory(Environment.getExternalStorageDirectory().getAbsolutePath()) //optional
                        .name("yachang")//optional
                        .build();
            } catch (SnappydbException e1) {
                e1.printStackTrace();
            }
        }
        super.onCreate();
        SDKInitializer.initialize(this);
        mContext = this;
        mQueue = Volley.newRequestQueue(this);


        /*CrashHandler catchExcep = new CrashHandler(this);
        Thread.setDefaultUncaughtExceptionHandler(catchExcep);*/
    }

    private RefWatcher refWatcher;
    public static RefWatcher getRefWatcher(Context context) {
        UsbApplication application = (UsbApplication) context.getApplicationContext();
        return application.refWatcher;
    }

    public static Context getContext(){
        return mContext;
    }

    public static RequestQueue getQueue(){
        return mQueue;
    }

    public static DB getDB(){
        return snappydb;
    }

}
